/**
 * @param {Function} fn - 实际运行的函数
 * @param {number} delay - 延迟时间
 * @returns {Function} - 返回的防抖函数
 */

const Public = {
    debounce(fn, delay) {
        return function(...args) {
            if (this.temp) clearTimeout(this.temp);
            this.temp = setTimeout(() => {
                fn.apply(null, args);
            }, delay);
        }.bind(this);
    },
    install(Vue) {
        Vue.prototype.$Public = {
            debounce: this.debounce
        };
        this.temp = null;
    }
}

export default Public;
